# -*- coding:utf-8 -*-
#! python3
from facecat import *
import os
import requests
from requests.adapters import HTTPAdapter
import timer

#更新悬浮状态
#views:视图集合
def updateView(views):
	updateViewDefault(views)

#绘制视图
#view:视图
#paint:绘图对象
#clipRect:区域
def onPaint(view, paint, clipRect):
	onPaintDefault(view, paint, clipRect)

#绘制视图边线
#view:视图
#paint:绘图对象
#clipRect:区域
def onPaintBorder(view, paint, clipRect):
	onPaintBorderDefault(view, paint, clipRect)

#视图的鼠标移动方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseMove(view, mp, buttons, clicks, delta):
	onMouseMoveDefault(view, mp, buttons, clicks, delta)
		
#视图的鼠标按下方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseDown(view, mp, buttons, clicks, delta):
	onMouseDownDefault(view, mp, buttons, clicks, delta)

#视图的鼠标抬起方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseUp(view, mp, buttons, clicks, delta):
	onMouseUpDefault(view, mp, buttons, clicks, delta)

#视图的鼠标点击方法
#view 视图
#firstTouch:是否第一次触摸 
#firstPoint:第一次触摸的坐标 
#secondTouch:是否第二次触摸 
#secondPoint:第二次触摸的坐标
#clicks 点击次数
def onClick(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks):
	onClickDefault(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks)

#视图的鼠标滚动方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseWheel(view, mp, buttons, clicks, delta):
	onMouseWheelDefault(view, mp, buttons, clicks, delta)

xml = ""
appPaint = FCPaint() #创建绘图对象
appPaint.defaultUIStyle = "dark"
appPaint.onPaint = onPaint 
appPaint.onPaintBorder = onPaintBorder
appPaint.onMouseDown = onMouseDown 
appPaint.onMouseMove = onMouseMove 
appPaint.onMouseUp = onMouseUp
appPaint.onMouseWheel = onMouseWheel
appPaint.onClick = onClick
appPaint.onUpdateView = updateView

#消息循环
def WndProc(hwnd,msg,wParam,lParam):
	return WndProcDefault(appPaint,hwnd,msg,wParam,lParam)

#初始化窗体
createMainWindow(appPaint, "facecat-py", WndProc)
xml = """<?xml version="1.0" encoding="utf-8"?>
<html xmlns="facecat">
    <head>
    </head>
    <body>
    <div type="splitlayout" name="divAll" candragsplitter="true" layoutstyle="toptobottom" dock="fill" size="400,505" splitterposition="0,80,400,80" bordercolor="none">
        <div type="tab" name="tabTradeAccount" bordercolor="none" backcolor="none">
        <div type="tabpage" name="pageTradeAccount" text="持仓" headersize="100,0" backcolor="none" bordercolor="none" padding="5,5,5,5">
            <table name="gridTradeAccount" dock="fill" headerheight="70" showhscrollbar="false" bordercolor="none" backcolor="-200000000163">
            <tr>
                <th name="colF1" text="静态权益" width="120" location="0,0" size="120,70" />
                <th name="colF2" text="平仓盈亏" width="120" />
                <th name="colF3" text="浮动盈亏" width="120" />
                <th name="colF4" text="持仓盈亏" width="120" location="240,0" size="120,70" />
                <th name="colF5" text="动态权益" width="120" />
                <th name="colF6" text="占用保证金" width="120" />
                <th name="colF7" text="下单冻结" width="120" />
                <th name="colF8" text="可用资金" width="120" />
                <th name="colF9" text="风险度" width="120" />
                <th name="colF10" text="冻结保证金" width="120" />
                <th name="colF11" text="冻结手续费" width="120" />
                <th name="colF12" text="手续费" width="120" />
                <th name="colF13" text="上次结算准备金" width="120" />
                <th name="colF14" text="上次信用额度" width="120" />
                <th name="colF15" text="上次质押金额" width="120" />
                <th name="colF16" text="质押金额" width="120" />
                <th name="colF17" text="今日出金" width="120" />
                <th name="colF18" text="今日入金" width="120" />
                <th name="colF19" text="信用金额" width="120" />
                <th name="colF20" text="保底资金" width="120" />
                <th name="colF21" text="可取资金" width="120" />
            </tr>
            </table>
        </div>
        </div>
        <div type="splitlayout" name="divBottom" candragsplitter="true" layoutstyle="bottomtotop" size="400,450" splitterposition="0,430,400,430" bordercolor="none" backcolor="none">
        <div name="divStatus" size="966,17">
            <label name="lblTradingTime" text="--" location="3,2" size="100,20" font="Default,12" />
            <label name="lbllog" text="--" location="105,2" size="352,20" font="Default,12" />
        </div>
        <div type="splitlayout" name="divMiddle" candragsplitter="true" layoutstyle="toptobottom" size="600,600" splitmode="percentsize" splitterposition="0,450,400,450" bordercolor="none" backcolor="none">
            <div type="splitlayout" name="divMiddleTop" candragsplitter="true" layoutstyle="bottomtotop" size="600,600" splitterposition="0,330,400,330" bordercolor="none" backcolor="none">
            <div bordercolor="none" padding="5,5,5,5" backcolor="none">
                <div type="splitlayout" name="divMain" dock="fill" candragsplitter="true" layoutstyle="lefttoright" size="420,420" splitterposition="310,0,310,300" bordercolor="none" backcolor="none">
                <div bordercolor="none" backcolor="none" padding="0,0,5,0">
                    <div type="tab" name="tabTradeMain" selectedindex="0" location="0,0" size="1166,270" dock="fill" backcolor="-200000000163">
                    <div type="tabpage" name="pageTrade" text="标准下单" backcolor="none" bordercolor="none">
                        <div name="divTrade" size="310,250" dock="fill" location="0,0" bordercolor="none" backcolor="Back">
                        <label name="lblContract" text="合约" location="8,18" size="37,20" font="Default,14" />
                        <label name="lblBuySell" text="买卖" location="8,49" size="38,19" font="Default,14" />
                        <input type="custom" cid="ribbonbutton2" name="btnOpenCloseMode" text="自动" location="3,76" size="46,20" />
                        <label name="lblVolume" text="手数" location="8,109" size="38,19" font="Default,14" />
                        <input type="radio" name="rbOpen" backcolor="rgba(43,138,195,100)" checked="true" text="开仓" location="52,76" size="65,20" groupname="OpenClose" />
                        <input type="radio" name="rbCloseToday" text="平今" location="120,76" size="65,20" groupname="OpenClose" />
                        <input type="radio" name="rbClose" text="平仓" location="182,76" size="65,20" groupname="OpenClose" />
                        <input type="radio" name="rbBuy" backcolor="rgba(255,0,0,100)" checked="true" text="买入" location="53,47" size="64,20" groupname="BuySell" />
                        <input type="radio" name="rbSell" text="卖出" location="119,47" size="64,20" groupname="BuySell" />
                        <input type="text" name="txtIssueCode" font="Default,20" location="53,11" size="163,28" lineheight="28" multiline="false" />
                        <input type="checkbox" name="cbLock" text="锁定" location="220,15" size="73,20" canfocus="false" buttonsize="16,16" />
                        <input type="range" name="spinVolume" font="Default,20" digit="0" location="52,102" size="115,28" lineheight="28" maximum="100000000" minimum="1" textalign="far" />
                        <input type="range" name="spinPrice" digit="2" font="Default,20" location="52,142" size="115,24" lineheight="28" maximum="100000000" textalign="far" />
                        <input type="custom" cid="ribbonbutton2" name="btnOrder" font="Default,16" text="下单" backcolor="rgb(15,193,118)" location="8,179" size="211,48" />
                        <input type="custom" cid="ribbonbutton2" name="btnCancel" text="取消" location="226,184" backcolor="rgb(248,73,96)" size="74,24" font="Default,12" />
                        <input type="custom" cid="ribbonbutton2" name="btnPreCondition" text="预埋/条件" location="226,209" size="74,23" font="Default,12" />
                        <label name="lblLess" text="&lt;=" location="185,104" size="26,21" font="Default,16" />
                        <label name="lblMaxVolume" text="0" location="206,104" size="16,21" font="Default,16" />
                        <label name="lblUp" text="0" location="188,121" size="100,20" opacity="1" />
                        <label name="lblAskPrice" text="0" location="188,135" size="53,20" />
                        <label name="lblBidPrice" text="0" location="188,149" size="51,21" />
                        <label name="lblDown" text="0" location="188,163" size="48,20" />
                        <label name="Label" text="/" location="241,136" size="17,20" font="Default,12" />
                        <label name="Label1" text="/" location="239,150" size="16,20" font="Default,12" />
                        <label name="lblAskVolume" text="0" location="250,136" size="57,18" />
                        <label name="lblBidVolume" text="0" location="250,150" size="57,20" />
                        <input type="custom" cid="ribbonbutton2" name="btnTradeMode" text="跟盘" location="3,143" size="46,20" />
                        </div>
                    </div>
                    </div>
                </div>
                <div type="splitlayout" name="divMain" dock="fill" candragsplitter="true" layoutstyle="righttoleft" size="420,420" splitterposition="100,0" bordercolor="none" backcolor="none">
                    <div bordercolor="none" backcolor="none" padding="5,0,0,0">
                    <div type="tab" name="tabOrder2" selectedindex="1" backcolor="-200000000163" dock="fill">
                        <div type="tabpage" name="pageChart" text="图形" bordercolor="none" backcolor="none">
                        <chart name="chart" dock="fill" />
                        </div>
                    </div>
                    </div>
                    <div type="tab" name="tabOrder" selectedindex="1" backcolor="-200000000163">
                    <div type="tabpage" name="pageAllOrders" text="所有委托单" backcolor="none" bordercolor="none">
                        <div type="splitlayout" name="divOrder" dock="fill" layoutstyle="bottomtotop" size="400,400" splitterposition="0,370,400,370" backcolor="none" bordercolor="none">
                        <div name="divDealRecordType" backcolor="none" bordercolor="none">
                            <input type="radio" name="rdAllOrders" groupname="allOrders" checked="true" location="0,6" text="全部单" size="100,20" />
                            <input type="radio" name="rdOrder" groupname="allOrders" location="100,6" text="挂单" size="100,20" />
                            <input type="radio" name="rdDeal" groupname="allOrders" location="200,6" text="已成交" size="100,20" />
                            <input type="radio" name="rdCancel" groupname="allOrders" location="300,6" text="已撤单/错单" size="120,20" />
                            <input type="custom" cid="ribbonbutton2" name="btnCancelOrder2" location="450,2" size="100,26" text="撤单" />
                            <input type="custom" cid="ribbonbutton2" name="btnCancelAllOrder2" location="570,2" size="100,26" text="全撤" />
                        </div>
                        <table name="gridOrder" dock="Fill" size="569,330" backcolor="none" bordercolor="none">
                            <tr>
                            <th name="colA1" columntype="text" text="报单编号" width="80" />
                            <th name="colA2" columntype="text" text="合约" width="80" />
                            <th name="colA3" columntype="text" horizontalalign="center" text="买卖" width="60" />
                            <th name="colA4" columntype="text" horizontalalign="center" text="开平" width="60" />
                            <th name="colA5" columntype="text" horizontalalign="center" text="挂单状态" width="140" />
                            <th name="colA6" columntype="double" horizontalalign="far" text="报单价格" width="80" />
                            <th name="colA7" columntype="int" horizontalalign="far" text="报单手数" width="80" />
                            <th name="colA8" columntype="int" horizontalalign="far" text="未成交手数" width="80" />
                            <th name="colA9" columntype="int" horizontalalign="far" text="成交手数" width="80" />
                            <th name="colA10" columntype="text" horizontalalign="center" text="报单时间" width="60" />
                            <th name="colA11" columntype="text" horizontalalign="center" text="最后成交时间" width="80" />
                            <th name="colA12" columntype="double" horizontalalign="far" text="成交均价" width="80" />
                            <th name="colA13" columntype="double" horizontalalign="far" text="冻结保证金" width="80" />
                            <th name="colA14" columntype="double" horizontalalign="far" text="冻结手续费" width="80" />
                            <th name="colA15" columntype="text" horizontalalign="center" text="投保" width="60" />
                            <th name="colA16" columntype="text" text="交易所" width="80" />
                            <th name="colA18" columntype="text" horizontalalign="center" text="报单价格条件" width="100" />
                            <th name="colA19" columntype="text" text="有效期类型" width="200" />
                            <th name="colA20" columntype="text" horizontalalign="center" text="报单类型" width="60" />
                            <th name="colA21" columntype="text" horizontalalign="center" text="是否强平" width="80" />
                            <th name="colA22" columntype="text" horizontalalign="center" text="强平原因" width="80" />
                            <th name="colA23" columntype="text" text="指令结果" width="80" />
                            <th name="colA24" columntype="text" text="客户端信息" width="80" />
                            <th name="colA25" columntype="text" text="撤单锁定" width="60" />
                            </tr>
                        </table>
                        </div>
                    </div>
                    <div type="tabpage" name="pageTradeRecord" text="成交记录" backcolor="none" bordercolor="none">
                        <div type="splitlayout" name="divTradeRecord" dock="fill" layoutstyle="bottomtotop" size="400,400" splitterposition="0,370,400,370" backcolor="none" bordercolor="none">
                        <div name="divTradeRecordType" backcolor="none" bordercolor="none">
                            <input type="radio" name="rdDetail" groupname="tradeRecordType" checked="true" location="0,5" text="明细" size="100,20" />
                            <input type="radio" name="rdSummary" groupname="tradeRecordType" location="100,5" text="合计" size="100,20" />
                        </div>
                        <div name="divTradeRecordInner" backcolor="none" bordercolor="none">
                            <table name="gridTradeRecord" dock="fill" backcolor="none" bordercolor="none">
                            <tr>
                                <th name="colR1" columntype="text" text="成交编号" width="80" />
                                <th name="colR2" columntype="text" text="合约" width="80" />
                                <th name="colR3" columntype="text" horizontalalign="center" text="买卖" width="60" />
                                <th name="colR4" columntype="text" horizontalalign="center" text="开平" width="60" />
                                <th name="colR5" columntype="double" horizontalalign="far" text="成交价格" width="80" />
                                <th name="colR6" columntype="int" horizontalalign="far" text="成交手数" width="80" />
                                <th name="colR7" columntype="text" horizontalalign="center" text="成交时间" width="80" />
                                <th name="colR8" columntype="text" horizontalalign="center" text="报单编号" width="80" />
                                <th name="colR9" columntype="text" horizontalalign="center" text="成交类型" width="80" />
                                <th name="colR10" columntype="text" horizontalalign="center" text="投保" width="60" />
                                <th name="colR11" columntype="text" text="交易所" width="80" />
                                <th name="colR12" columntype="double" horizontalalign="far" text="手续费" width="80" />
                            </tr>
                            </table>
                            <table name="gridTradeStatistics" dock="fill" visible="false" backcolor="none" bordercolor="none">
                            <tr>
                                <th name="colS1" columntype="text" text="合约" width="80" />
                                <th name="colS2" columntype="text" text="交易所" width="80" />
                                <th name="colS3" columntype="text" horizontalalign="center" text="买卖" width="80" />
                                <th name="colS4" columntype="text" horizontalalign="center" text="开平" width="80" />
                                <th name="colS5" columntype="double" horizontalalign="far" text="成交均价" width="100" />
                                <th name="colS6" columntype="int" horizontalalign="far" text="成交手数" width="100" />
                                <th name="colS7" columntype="double" horizontalalign="far" text="手续费" width="100" />
                                <th name="colS8" columntype="text" horizontalalign="center" text="投保" width="60" />
                            </tr>
                            </table>
                        </div>
                        </div>
                    </div>
                    </div>
                </div>
                </div>
            </div>
            <div bordercolor="none" backcolor="none" padding="5,5,5,5">
                <div type="tab" name="tabQuote" selectedindex="0" size="400,400" backcolor="-200000000163" dock="fill">
                <div type="tabpage" name="pagePageQuote" text="报价表" bordercolor="none" backcolor="none">
                    <table name="gridLatestData" dock="fill" location="0,0" size="914,160" bordercolor="none" backcolor="none">
                    <tr>
                        <th name="colQ1" columntype="text" text="合约" width="80" />
                        <th name="colQ2" columntype="text" text="合约名" width="100" />
                        <th name="colQ3" columntype="double" horizontalalign="far" text="最新价" width="60" />
                        <th name="colQ4" columntype="double" horizontalalign="far" text="涨跌" width="60" />
                        <th name="colQ5" columntype="double" horizontalalign="far" text="买价" width="60" location="300,0" size="60,20" />
                        <th name="colQ6" columntype="int" horizontalalign="far" text="买量" width="60" location="360,0" size="60,20" />
                        <th name="colQ7" columntype="double" horizontalalign="far" text="卖价" width="60" />
                        <th name="colQ8" columntype="int" horizontalalign="far" text="卖量" width="60" />
                        <th name="colQ9" columntype="int" horizontalalign="far" text="成交量" width="60" />
                        <th name="colQ10" columntype="int" horizontalalign="far" text="持仓量" width="60" />
                        <th name="colQ11" columntype="double" horizontalalign="far" text="涨停价" width="60" />
                        <th name="colQ12" columntype="double" horizontalalign="far" text="涨停价" width="60" />
                        <th name="colQ13" columntype="double" horizontalalign="far" text="今开盘" width="60" />
                        <th name="colQ14" columntype="double" horizontalalign="far" text="昨结算" width="60" />
                        <th name="colQ15" columntype="double" horizontalalign="far" text="最高价" width="60" />
                        <th name="colQ16" columntype="double" horizontalalign="far" text="最低价" width="60" />
                        <th name="colQ17" columntype="int" horizontalalign="far" text="现量" width="60" />
                        <th name="colQ18" columntype="percent" horizontalalign="far" text="涨跌幅" width="60" />
                        <th name="colQ19" columntype="double" horizontalalign="far" text="昨收盘" width="60" />
                        <th name="colQ20" columntype="thousands" horizontalalign="far" text="成交额" width="100" />
                        <th name="colQ21" columntype="text" text="交易所" width="60" />
                        <th name="colQ22" columntype="text" horizontalalign="center" text="行情更新时间" width="100" />
                        <th name="colQ23" columntype="double" text="昨持仓量" width="60" />
                        <th name="colQ24" columntype="double" text="今收盘" width="60" />
                        <th name="colQ25" columntype="double" text="结算价" width="60" />
                        <th name="colQ26" columntype="double" text="当日均价" width="80" />
                        <th name="colQ27" columntype="int" text="持仓增减" width="80" />
                        <th name="colQ28" columntype="double" text="组合买价" width="80" />
                        <th name="colQ29" columntype="int" text="组合买量" width="80" />
                        <th name="colQ30" columntype="double" text="组合卖价" width="80" />
                        <th name="colQ31" columntype="int" text="组合卖量" width="80" />
                        <th name="colQ32" columntype="int" text="撤单次数" width="80" />
                    </tr>
                    </table>
                </div>
                <div type="tabpage" name="pageContracts" text="合约列表" bordercolor="none" backcolor="none">
                    <table name="gridContracts" dock="fill" bordercolor="none" backcolor="none">
                    <tr>
                        <th name="colC1" columntype="text" text="品种代码" width="80" />
                        <th name="colC2" columntype="text" text="合约" width="60" />
                        <th name="colC3" columntype="text" text="合约名" width="100" />
                        <th name="colC4" columntype="text" text="交易所" width="60" />
                        <th name="colC5" columntype="int" horizontalalign="far" text="合约乘数" width="100" />
                        <th name="colC6" columntype="double" horizontalalign="far" text="最小价格变动单位" width="100" />
                        <th name="colC7" columntype="text" horizontalalign="center" text="品种类型" width="100" />
                        <th name="colC8" columntype="text" horizontalalign="center" text="最后日期" width="100" />
                        <th name="colC9" columntype="percent" horizontalalign="far" text="多头保证金率" width="100" />
                        <th name="colC10" columntype="percent" horizontalalign="far" text="空头保证金率" width="100" />
                        <th name="colC11" columntype="double" horizontalalign="far" text="开仓手续费" width="100" />
                        <th name="colC12" columntype="double" horizontalalign="far" text="平仓手续费" width="100" />
                        <th name="colC13" columntype="double" horizontalalign="far" text="平今手续费" width="100" />
                        <th name="colC14" columntype="percent" horizontalalign="far" text="开仓手续费率" width="100" />
                        <th name="colC15" columntype="percent" horizontalalign="far" text="平仓手续费率" width="100" />
                        <th name="colC16" columntype="percent" horizontalalign="far" text="平今手续费率" width="100" />
                        <th name="colC17" columntype="int" horizontalalign="far" text="市价单最大下单量" width="100" />
                        <th name="colC18" columntype="int" horizontalalign="far" text="限价单最大下单量" width="100" />
                    </tr>
                    </table>
                </div>
                </div>
            </div>
            </div>
            <div bordercolor="none" padding="5,5,5,5" backcolor="-200000000163">
            <div type="tab" name="tabInvestorPosition" selectedindex="0" dock="fill" backcolor="none">
                <div type="tabpage" name="pagePageInvestorPosition" text="持仓" bordercolor="none" backcolor="none">
                <div type="splitlayout" name="divInvestorPosition" dock="fill" layoutstyle="bottomtotop" size="400,400" splitterposition="0,370,400,370" bordercolor="none" backcolor="none">
                    <div name="divInvestorPositionBottom" bordercolor="none" backcolor="none">
                    <input type="radio" name="cbInvestorPosition" checked="true" location="5,5" groupname="InvestorPosition" size="80,20" text="持仓" />
                    <input type="radio" name="cbInvestorPositionDetail" groupname="InvestorPosition" location="80,5" size="80,20" text="持仓明细" />
                    <input type="radio" name="cbCompPosition" groupname="InvestorPosition" location="180,3" size="80,23" text="组合持仓" visible="false" />
                    <input type="custom" cid="ribbonbutton2" name="btnOpenInterestIP" location="300,3" size="80,23" text="对价平仓" height="24" />
                    <input type="custom" cid="ribbonbutton2" name="btnMarketPositionIP" location="390,3" size="80,23" text="市价平仓" height="24" />
                    <input type="custom" cid="ribbonbutton2" name="btnMarketBackhandIP" location="480,3" size="80,23" text="市价反手" height="24" />
                    </div>
                    <div name="divInvestorPositionTop" bordercolor="none" backcolor="none">
                    <table name="gridInvestorPosition" dock="fill" bordercolor="none" backcolor="none">
                        <tr>
                        <th name="colP1" columntype="text" text="合约" width="80" />
                        <th name="colP2" columntype="text" horizontalalign="center" text="多空" width="60" />
                        <th name="colP3" columntype="int" horizontalalign="far" text="总持仓" width="60" />
                        <th name="colP4" columntype="int" horizontalalign="far" text="昨仓" width="60" />
                        <th name="colP5" columntype="int" horizontalalign="far" text="今仓" width="60" />
                        <th name="colP6" columntype="int" horizontalalign="far" text="可平量" width="60" />
                        <th name="colP7" columntype="double" horizontalalign="far" text="持仓均价" width="80" />
                        <th name="colP8" columntype="thousands" horizontalalign="far" text="持仓盈亏" width="150" />
                        <th name="colP9" columntype="thousands" horizontalalign="far" text="占用保证金" width="100" />
                        <th name="colP10" columntype="text" horizontalalign="center" text="投保" width="60" />
                        <th name="col111" columntype="text" text="交易所" width="80" />
                        <th name="colP12" columntype="int" horizontalalign="far" text="总多仓" width="60" />
                        <th name="colP13" columntype="int" horizontalalign="far" text="总空仓" width="60" />
                        <th name="colP14" columntype="int" horizontalalign="far" text="今多仓" width="60" />
                        <th name="colP15" columntype="int" horizontalalign="far" text="今空仓" width="60" />
                        <th name="colP16" columntype="int" horizontalalign="far" text="总可平今量" width="100" />
                        <th name="colP17" columntype="int" horizontalalign="far" text="总可平仓量" width="100" />
                        <th name="colP18" columntype="int" horizontalalign="far" text="平今挂单量" width="100" />
                        <th name="colP19" columntype="int" horizontalalign="far" text="平仓挂单量" width="100" />
                        <th name="colP20" columntype="int" horizontalalign="far" text="组合冻结量" width="100" />
                        <th name="colP21" columntype="int" horizontalalign="far" text="可平今量" width="80" />
                        <th name="col122" columntype="int" horizontalalign="far" text="可平仓量" width="80" />
                        <th name="colP23" columntype="double" horizontalalign="far" text="开仓均价" width="100" />
                        <th name="colP24" columntype="double" horizontalalign="far" text="多头开仓价" width="100" />
                        <th name="colP25" columntype="double" horizontalalign="far" text="空头开仓价" width="100" />
                        <th name="colP26" columntype="thousands" horizontalalign="far" text="浮动盈亏" width="100" />
                        <th name="colP27" columntype="thousands" horizontalalign="far" text="总盈亏" width="80" />
                        <th name="colP28" columntype="int" horizontalalign="far" text="今开仓量" width="80" />
                        <th name="colP29" columntype="int" horizontalalign="far" text="今平仓量" width="80" />
                        <th name="colP30" columntype="double" horizontalalign="far" text="现价" width="80" />
                        <th name="colP31" columntype="double" horizontalalign="far" text="最新差价" width="80" />
                        </tr>
                    </table>
                    <table name="gridInvestorPositionDetail" dock="fill" visible="false" bordercolor="none" backcolor="none">
                        <tr>
                        <th name="colT1" columntype="text" text="成交编号" width="80" />
                        <th name="colT2" columntype="text" text="合约" width="80" />
                        <th name="colT3" columntype="text" horizontalalign="center" text="多空" width="60" />
                        <th name="colT4" columntype="int" horizontalalign="far" text="手数" width="60" />
                        <th name="colT5" columntype="double" horizontalalign="far" text="开仓价" width="80" />
                        <th name="colT6" columntype="thousands" horizontalalign="far" text="占用保证金" width="100" />
                        <th name="colT7" columntype="text" text="持仓类型" width="80" />
                        <th name="colT8" columntype="text" horizontalalign="center" text="投保" width="60" />
                        <th name="colT9" columntype="text" horizontalalign="center" text="开仓时间" width="100" />
                        <th name="colT10" columntype="thousands" horizontalalign="far" text="持仓盈亏" width="100" />
                        <th name="colT11" columntype="thousands" horizontalalign="far" text="平仓盈亏" width="100" />
                        <th name="colT12" columntype="text" text="交易所" width="80" />
                        <th name="colT13" columntype="text" text="组合状态" width="100" />
                        <th name="colT14" columntype="double" horizontalalign="far" text="昨结算" width="80" />
                        <th name="colT15" columntype="int" horizontalalign="far" text="平仓量" width="80" />
                        <th name="colT16" columntype="thousands" horizontalalign="far" text="浮动盈亏" width="100" />
                        <th name="colT17" columntype="double" horizontalalign="far" text="最新价" width="80" />
                        <th name="colT18" columntype="int" horizontalalign="far" text="组合合约代码" width="100" />
                        </tr>
                    </table>
                    <table name="gridInvestorCombinePositionDetail" dock="fill" visible="false" bordercolor="none" backcolor="none">
                        <tr>
                        <th name="colM1" columntype="text" text="合约" width="120" />
                        <th name="colM2" columntype="text" horizontalalign="center" text="买卖" width="60" />
                        <th name="colM3" columntype="int" horizontalalign="far" text="手数" width="60" />
                        <th name="colM4" columntype="double" horizontalalign="far" text="开仓均价" width="100" />
                        <th name="colM5" columntype="text" horizontalalign="center" text="投保" width="60" />
                        </tr>
                    </table>
                    </div>
                </div>
                </div>
            </div>
            </div>
        </div>
        </div>
    </div>
    </body>
</html>"""
renderFaceCat(appPaint, xml)

room = "1234"
pwd = "1234"
lastIndex = -1

def changeTheme(a='', b=''):
    global appPaint
    global xml
    global lastIndex
    global room
    global lastIndex
    result = requests.get("http://127.0.0.1:9962?func=fcscript&funcname=getChatData('" + room + "','" + pwd + "'," + str(lastIndex)+ ");").text
    if len(result) > 0 and result != "-1,-1":
        strs = result.split(",")
        if appPaint.defaultUIStyle == "dark":
            appPaint.defaultUIStyle = "light"
        else:
            appPaint.defaultUIStyle = "dark"
        appPaint.views = []
        renderFaceCat(appPaint, xml)
        lastIndex = int(strs[0])

#开启秒表
timer.set_timer(100, changeTheme)
showWindow(appPaint)